﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Chisholm.Windows.Live.Library;
using System.ServiceModel.Channels;

namespace Chisholm.Windows.Live.SSOClient
{
    /// <summary>
    /// This is the wrapper class which provides base level access to the Windows Live SSO Server
    /// </summary>
    internal class SSOServerClient : ClientBase<ISSOServerEngine>, ISSOServerEngine
    {
        /// <summary>
        /// This initialises the client connection to the given server using the given binding
        /// </summary>
        /// <param name="binding">The type of binding to use to connect</param>
        /// <param name="endpoint">The end point to connect to</param>
        public SSOServerClient(Binding binding, EndpointAddress endpoint) : 
            base(binding, endpoint)
        {           
        }

        /// <summary>
        /// This method authenticates the given Windows Live ID against the source server and returns
        /// the Short Lived Token (or an empty string if the user couldn't be authenticated)
        /// </summary>
        /// <param name="windowsliveid">The windows live ID of the user to authenticate</param>
        /// <returns>Either the issued Short Lived Token, or an empty string if an error occurred</returns>
        public string GetSLT(string windowsliveid)
        {
            return base.Channel.GetSLT(windowsliveid);
        }

        /// <summary>
        /// This method authenticates the given Windows Live ID against the source server and then, 
        /// depending on the desired service chosen, returns the redirection URL to that service with
        /// the short lived token and Windows Live ID embedded
        /// </summary>
        /// <param name="windowsliveid">The Windows Live ID of the user to authenticate</param>
        /// <param name="desiredservice">The desired service to access</param>
        /// <returns>The pre-prepared URL ready for redirection</returns>
        public string GetRedirectionURL(string windowsliveid, LiveServiceTypes desiredservice)
        {
            return base.Channel.GetRedirectionURL(windowsliveid, desiredservice);
        }
    }
}
